<?php
namespace backend\modules\admin\models\permission\search;
use common\models\User;
use yii\data\ActiveDataProvider;

/**
 * Class MemberSearch
 *
 * @package backend\modules\admin\models\permission\search
 */
class MemberSearch extends User
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['username','mobile'],'required'],
            [['created_time','updated_time'],'safe'],
            ['email','email'],
            [['mobile'],'string'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'username'  => '用户名',
            'mobile'    => '手机号',
            'email'     => '邮箱',
            'avatar'    => '头像',
            'created_time'=>'创建时间',
            'status'      => '状态'
        ];
    }

    public function search($params)
    {
        $query = self::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination'=>[
                'pageSize'=>20
            ]
        ]);
        if (!$this->load($params)) {
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'username', $this->username]);
        $query->andFilterWhere(['like', 'mobile', $this->mobile]);
        return $dataProvider;
    }
}
